﻿/********************************************************************
FileName    :   Bll_OS.cs
CreateTime  :   2020-09-26 11:44:21
BaseClass   :   Bll_OS
FileType    :   .cs
Author      :  minjie
Description :   Bll_OS层（简单三层）
*********************************************************************/

using System;
using System.Text;
using System.Collections.Generic;

using System.Data;
using OS.DAL;
using System.Runtime.InteropServices;

namespace OS.BLL
{
    /// <summary>
    /// Bll_sys_DICTIONARY的摘要说明。
    /// </summary>
    public partial class Bll_view_Spda
    {

        private readonly Dal_view_Spda dal = new Dal_view_Spda();
        public Bll_view_Spda()
        { }

        #region  Method 

        public bool Exists(string spbh)
        {
            return dal.Exists(spbh);
        }

        /// <summary> 
        /// 得到一个对象实体 
        /// </summary> 
        public view_Spda_Entity GetModel(string spbh)
        {

            return dal.GetModel(spbh);
        }

        /// <summary> 
        /// 获得数据列表 
        /// </summary> 
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }


        /// <summary> 
        /// 获得数据列表 
        /// </summary> 
        public List<view_Spda_Entity> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary> 
        /// 获得数据列表 
        /// </summary> 
        public List<view_Spda_Entity> GetModelList(string strWhere, string orderby, int startIndex, int endIndex)
        {
            DataSet ds = dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary> 
        /// 获得数据列表 
        /// </summary> 
        public List<view_Spda_Entity> DataTableToList(DataTable dt)
        {
            List<view_Spda_Entity> modelList = new List<view_Spda_Entity>();
            if (dt != null)
            {
                int rowsCount = dt.Rows.Count;
                if (rowsCount > 0)
                {
                    view_Spda_Entity model;
                    for (int n = 0; n < rowsCount; n++)
                    {
                        model = new view_Spda_Entity();

                        if (dt.Rows[n]["DjLsh"] != null && dt.Rows[n]["DjLsh"].ToString() != "")
                            model.DjLsh = int.Parse(dt.Rows[n]["DjLsh"].ToString());

                        model.spbh = dt.Rows[n]["spbh"].ToString();
                        model.spmc = dt.Rows[n]["spmc"].ToString();
                        model.tmh = dt.Rows[n]["tmh"].ToString();
                        model.flmc = dt.Rows[n]["flmc"].ToString();
                        model.tpdz = dt.Rows[n]["tpdz"].ToString();

                        if (dt.Rows[n]["lsj"] != null && dt.Rows[n]["lsj"].ToString() != "")
                            model.lsj = decimal.Parse(dt.Rows[n]["lsj"].ToString());


                        if (dt.Rows[n]["pfj"] != null && dt.Rows[n]["pfj"].ToString() != "")
                            model.pfj = decimal.Parse(dt.Rows[n]["pfj"].ToString());


                        if (dt.Rows[n]["jj"] != null && dt.Rows[n]["jj"].ToString() != "")
                            model.jj = decimal.Parse(dt.Rows[n]["jj"].ToString());

                        if (dt.Rows[n]["kcsl"] != null && dt.Rows[n]["kcsl"].ToString() != "")
                            model.kcsl = decimal.Parse(dt.Rows[n]["kcsl"].ToString());


                        if (dt.Rows[n]["xgsj"] != null && dt.Rows[n]["xgsj"].ToString() != "")
                            model.xgsj = DateTime.Parse(dt.Rows[n]["xgsj"].ToString());
                        else
                            model.xgsj = DateTime.Now.AddYears(-30);

                        if (dt.Rows[n]["djsj"] != null && dt.Rows[n]["djsj"].ToString() != "")
                            model.djsj = DateTime.Parse(dt.Rows[n]["djsj"].ToString());
                        else
                            model.xgsj = DateTime.Now.AddYears(-30);

                        if(dt.Columns.Contains("ckbh"))
                        model.ckbh = dt.Rows[n]["ckbh"].ToString();

                        if (dt.Columns.Contains("ckmc"))
                            model.ckmc = dt.Rows[n]["ckmc"].ToString();

       



        modelList.Add(model);
                    }
                }
            }
            return modelList;
        }

        /// <summary> 
        /// 获得数据列表 
        /// </summary> 
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary> 
        /// 批量处理 
        /// </summary> 
        public int ExecuteSqlTran(List<string> ls, ref string error)
        {
            return dal.ExecuteSqlTran(ls, ref error);
        }

        /// <summary> 
        /// 直接执行sql语句 
        /// </summary> 
        public int ExecuteSql(string sql)
        {
            return dal.ExecuteSql(sql);
        }

        /// <summary> 
        /// 直接执行sql语句 
        /// </summary> 
        public string GetSingle(string sql)
        {
            return dal.GetSingle(sql);
        }

        /// <summary> 
        /// 直接执行sql语句 
        /// </summary> 
        public DataTable ExecuteDt(string sql)
        {
            return dal.ExecuteDt(sql);
        }

        /// <summary> 
        /// 获取记录总数 
        /// </summary> 
        public int GetRecordCount(string strWhere)
        {
            return dal.GetRecordCount(strWhere);
        }
        #endregion

    }

}
